package com.yami.shop.admin.controller;

import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.common.util.PageParam;

import com.yami.shop.dao.UserMapper;
import com.yami.shop.service.PostLikeRecordService;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.yami.shop.bean.model.PostLikeRecord;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;

/**
 * <p>
 * 动态喜欢记录 前端控制器
 * </p>
 *
 * @author chajiu
 * @since 2021-06-29
 */
@RestController
@RequestMapping("/post-like-record")
public class PostLikeRecordController {


    @Autowired
    private com.yami.shop.service.PostLikeRecordService PostLikeRecordService;
    /*@Autowired
    private UserMapper userMapper;*/

    /**
     * 分页获取
    */
     @GetMapping("/page")
     @PreAuthorize("@pms.hasPermission('admin:PostLikeRecord:page')")
     public ResponseEntity<IPage<PostLikeRecord>> page(PostLikeRecord postLikeRecord,PageParam<PostLikeRecord> page) {
         IPage<PostLikeRecord> iPage = PostLikeRecordService.page(page, new LambdaQueryWrapper<PostLikeRecord>());
         /*for(PostLikeRecord pages : iPage.getRecords()){
             pages.setUser(userMapper.selectById(pages.getUserId()));
         }*/
         return ResponseEntity.ok(iPage);
     }

    /**
     * 保存
     */
    @PostMapping("/save")
    @PreAuthorize("@pms.hasPermission('admin:PostLikeRecord:save')")
    public ResponseEntity<Void> save(@RequestBody PostLikeRecord postLikeRecord) {
        PostLikeRecordService.save(postLikeRecord);
        return ResponseEntity.ok().build();
    }

    /**
     * 获取信息
     */
    @GetMapping("/info/{id}")
    @PreAuthorize("@pms.hasPermission('admin:PostLikeRecord:info')")
    public ResponseEntity<PostLikeRecord> info(@PathVariable("id") String id){
        PostLikeRecord PostLikeRecord = PostLikeRecordService.getById(id);
            return ResponseEntity.ok(PostLikeRecord);
    }

    /**
     * 修改
     */
    @PutMapping
    @PreAuthorize("@pms.hasPermission('admin:PostLikeRecord:update')")
    public ResponseEntity<Void> update(@RequestBody PostLikeRecord postLikeRecord){
        PostLikeRecordService.updateById(postLikeRecord);
            return ResponseEntity.ok().build();
    }

    /**
     * 删除
     */
    @DeleteMapping
    @PreAuthorize("@pms.hasPermission('admin:PostLikeRecord:delete')")
    public ResponseEntity<Void> delete(@RequestBody String[]ids){
        PostLikeRecordService.removeByIds(Arrays.asList(ids));
            return ResponseEntity.ok().build();
    }


}

